package com.example.demo.converter;

import com.example.demo.dao.Cloth;
import com.example.demo.dto.ClothDTO;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

public class ClothConverter {
    public static ClothDTO convertCloth(Cloth cloth) {
        ClothDTO clothDTO = new ClothDTO();
        clothDTO.setId(cloth.getId());
        clothDTO.setCategory(cloth.getCategory());
        clothDTO.setSubcategory(cloth.getSubcategory());
        clothDTO.setImageBytes(cloth.getImageBytes());
        clothDTO.setImageName(cloth.getImageName());
        clothDTO.setClothName(cloth.getClothName());
        clothDTO.setUserClothId(cloth.getUserClothId());
        clothDTO.setModelUrl(cloth.getModelUrl());
        clothDTO.setPurchaseLink(cloth.getPurchaseLink());
        clothDTO.setUserDTO(UserConverter.convertUser(cloth.getUser()));
        return clothDTO;
    }
    public static Cloth convertCloth(ClothDTO clothDTO) {
        Cloth cloth = new Cloth();
        cloth.setId(clothDTO.getId());
        cloth.setCategory(clothDTO.getCategory());
        cloth.setSubcategory(clothDTO.getSubcategory());
        cloth.setImageName(clothDTO.getImageName());
        cloth.setImageBytes(clothDTO.getImageBytes());
        cloth.setClothName(clothDTO.getClothName());
        cloth.setUserClothId(clothDTO.getUserClothId());
        cloth.setModelUrl(clothDTO.getModelUrl());
        cloth.setPurchaseLink(clothDTO.getPurchaseLink());
        cloth.setUser(UserConverter.convertUser(clothDTO.getUserDTO()));
        return cloth;
    }
    public static Set<ClothDTO> convertToClothDTOSet(Set<Cloth> clothes) {
        if (clothes == null) {
            return Collections.emptySet();
        }
        return clothes.stream()
                .map(ClothConverter::convertCloth)
                .collect(Collectors.toSet());
    }

    public static Set<Cloth> convertToClothSet(Set<ClothDTO> clothes) {
        if (clothes == null) {
            return Collections.emptySet();
        }
        return clothes.stream()
                .map(ClothConverter::convertCloth)
                .collect(Collectors.toSet());
    }


}
